<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>文字转图片</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background: linear-gradient(135deg, #6e8efb, #a777e3);
            margin: 0;
            padding: 0;
            color: #333;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
        }

        form {
            background: #fff;
            padding: 20px;
            border-radius: 10px;
            box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
            text-align: center;
            width: 100%;
            max-width: 400px;
            display: flex;
            flex-direction: column;
            align-items: center;
        }

        textarea {
            width: 100%;
            height: 100px;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 5px;
            resize: none;
            font-size: 16px;
            box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1);
            margin-bottom: 15px;
        }

        textarea:focus {
            outline: none;
            border-color: #6e8efb;
            box-shadow: inset 0 1px 4px rgba(110, 142, 251, 0.5);
        }

        button {
            padding: 10px 20px;
            background: linear-gradient(90deg, #6e8efb, #a777e3);
            border: none;
            border-radius: 25px;
            color: white;
            font-size: 16px;
            cursor: pointer;
            transition: all 0.3s ease;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }

        button:disabled {
            background: #ddd;
            cursor: not-allowed;
        }

        button:hover:not(:disabled) {
            box-shadow: 0 6px 12px rgba(110, 142, 251, 0.4);
        }

        .loading {
            font-size: 14px;
            color: #888;
            margin-top: 10px;
        }

        hr {
            margin: 20px 0;
            border: none;
            height: 1px;
            background: #eee;
            width: 100%;
        }

        #ttsResponse img {
            max-width: 100%;
            border-radius: 10px;
            margin-top: 10px;
        }
    </style>
</head>
<body>
<form id="ttsForm">
    <textarea name="input" id="ttsTextarea" placeholder="请输入文字描述" required></textarea>
    <button type="submit" id="submitBtn">生成图片</button>
    <hr>
    <div id="ttsResponse"></div>
</form>

<script src="./jquery.min.js"></script>
<script>
    $("#ttsForm").submit(function(event) {
        event.preventDefault();
        if ($("#ttsTextarea").val().length < 5) {
            alert("文本太短了");
        } else {
            $("#submitBtn").prop('disabled', true);

            $("#ttsResponse").html('<div class="loading">图片生成中，请稍候...</div>');
            $.get("/ai/image/" + $("#ttsTextarea").val(), {}, function(resp) {
                $("#ttsResponse").html(`
                        <img src="${resp}">
                    `);
            }).always(function() {
                $("#submitBtn").prop('disabled', false);
            });
        }
    });
</script>
</body>
</html>
